package com.excel.strategy;

import com.alibaba.excel.write.handler.context.CellWriteHandlerContext;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import lombok.extern.slf4j.Slf4j;
import javax.validation.constraints.NotNull;
import java.util.Objects;

/**
 * @Description EvalReportResultWriteStyleStrategy
 * @Author fuhao
 * @CreateTime 2024/12/10 13:21
 */
@Slf4j
public class EvalReportResultWriteStyleStrategy extends HorizontalCellStyleStrategy {

//    private final WriteCellStyle headWriteCellStyle;
//    private final WriteCellStyle contentWriteCellStyle;
//    private final ExcelStyleContext styleContext;

//    public EvalReportResultWriteStyleStrategy(WriteCellStyle headWriteCellStyle,
//                                              WriteCellStyle contentWriteCellStyle,
//                                              ExcelStyleContext styleContext) {
//        this.headWriteCellStyle = headWriteCellStyle;
//        this.contentWriteCellStyle = contentWriteCellStyle;
//        this.styleContext = styleContext;
//    }

    @Override
    protected void setHeadCellStyle(CellWriteHandlerContext context) {
        if (stopProcessing(context)) {
            return;
        }
//        FuncUtil.handleIfTrue(styleContext.getRowIndexes().contains(context.getRowIndex()), () -> {
//            getHeaderCellStyle(context);
//            WriteCellStyle.merge(headWriteCellStyle, context.getFirstCellData().getOrCreateStyle());
//        });
    }

    @Override
    protected void setContentCellStyle(CellWriteHandlerContext context) {
//        FuncUtil.handleIfTrue(styleContext.getRowIndexes().contains(context.getRowIndex()), () -> {
//            getContentCellStyle(context);
//            WriteCellStyle.merge(contentWriteCellStyle, context.getFirstCellData().getOrCreateStyle());
//        });
    }


    @NotNull
    private void getHeaderCellStyle(CellWriteHandlerContext context) {
//        headWriteCellStyle.setFillForegroundColor(IndexedColors.PALE_BLUE.getIndex());
//        headWriteCellStyle.setWriteFont(ExcelStyleTool.defaultFontStyle());
//        try {
//            ExcelSheet excelSheet = styleContext.getExcelSheetList().get(context.getWriteSheetHolder().getSheetNo());
//            FuncUtil.handleIfTrue(Objects.nonNull(excelSheet) &&
//                    styleContext.getRowIndexes().contains(context.getRowIndex()), () -> {
//                List<ExcelCell> excelCellList = excelSheet.getExcelCellList();
//                headWriteCellStyle.setFillForegroundColor(
//                        excelCellList.get(context.getColumnIndex()).getHeadFillForegroundColor()
//                );
//            });
//        } catch (Exception e) {
//            log.error("====getHeaderCellStyle===:{}", e);
//        }
    }

    @NotNull
    private void getContentCellStyle(CellWriteHandlerContext context) {
//        contentWriteCellStyle.setFillForegroundColor(IndexedColors.PALE_BLUE.getIndex());
//        contentWriteCellStyle.setWriteFont(ExcelStyleTool.defaultFontStyle());
//        try {
//            ExcelSheet excelSheet = styleContext.getExcelSheetList().get(context.getWriteSheetHolder().getSheetNo());
//            FuncUtil.handleIfTrue(Objects.nonNull(excelSheet) &&
//                    styleContext.getRowIndexes().contains(context.getRowIndex()), () -> {
//                List<ExcelCell> excelCellList = excelSheet.getExcelCellList();
//                Short headFillForegroundColor = excelCellList.get(context.getColumnIndex()).getHeadFillForegroundColor();
//                /**
//                 * Setting to one fills the cell with the foreground color... No idea about other values
//                 * 设置为1会用前景颜色填充单元格
//                 */
//                contentWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
//                contentWriteCellStyle.setFillForegroundColor(headFillForegroundColor);
//                contentWriteCellStyle.setFillBackgroundColor(headFillForegroundColor);
//            });
//        } catch (Exception e) {
//            log.error("====getContentCellStyle===:{}", e);
//        }
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof EvalReportResultWriteStyleStrategy)) {
            return false;
        }
        if (!super.equals(o)) {
            return false;
        }
        return true;
//        EvalReportResultWriteStyleStrategy that = (EvalReportResultWriteStyleStrategy) o;
//        return Objects.equals(headWriteCellStyle, that.headWriteCellStyle) &&
//                Objects.equals(contentWriteCellStyle, that.contentWriteCellStyle) &&
//                Objects.equals(styleContext, that.styleContext);
    }

    @Override
    public int hashCode() {
//        return Objects.hash(super.hashCode(), headWriteCellStyle, contentWriteCellStyle, styleContext);
        return Objects.hash(super.hashCode());
    }
}
